package com.atguigu.gmall.mq.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayMqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/mq")
public class MqSendController {

    @Autowired
    RabbitService rabbitService;

    @GetMapping("/sendMessage")
    public Result sendMessage(String message){
        rabbitService.sendMessage("exchange111","routingKey",message);
        return Result.ok();
    }
    @GetMapping("/sendMessage2")
    public Result sendMessage2(String message){
        rabbitService.sendMessage("exchange222","routingKey222",message);
        return Result.ok();
    }

    @GetMapping("/sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String msg){
        rabbitService.sendDeadLetterMessage(msg, DeadLetterMqConfig.exchange_dead,DeadLetterMqConfig.routing_dead_1,15);
        return Result.ok();
    }

    //发送延迟消息 （基于延迟插件的）
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        rabbitService.sendDelayMessage(DelayMqConfig.exchange_delay,DelayMqConfig.routing_delay,message,9);
        return Result.ok();
    }
}
